home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Window.h
-
- Contains: Definition of TWindow, a base class which provides a
- framework for building way-cool windows which even John
- Sullivan would be happy with. Floating windows and “smart
- zooming” algorithms are based on code samples provided by
- Dean Yu.
-
- Written by: Dave Falkenburg, Dean Yu
-
- Copyright: © 1993-1995 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <8> 1/24/95 DRF Make DoMenuSelection return a Boolean, just like DoMenuCommand.
- <7> 1/20/95 DRF Add a field to track whether a TWindow needs to be disposed via
- DisposeDialog. Thanks to Gary W. Powell @ Adobe for reporting
- the bug.
- <6> 1/3/95 DRF Add Nitin’s changes for Drag handling: a ClickAndDrag method.
- <5> 1/3/95 DRF Protected TWindow::Window because it is not legal to create a
- TWindow without subclassing. Also revised DoMenuSelection to use
- a typedef-ed parameter.
- <4> 11/12/94 DRF Added AdjustMenusBeforeMenuSelection.
- <3> 11/8/94 DRF Add some better menu handling methods.
- <2> 9/4/94 DRF Added DrawJustTheGrowIcon.
- */
-
- #ifndef _WINDOW_
- #define _WINDOW_
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef _MENUBAR_
- #include "MenuBar.h"
- #endif
-
-
- typedef short WindowTemplateID;
-
-
- class TWindow
- {
- protected:
- // protect the constructor because it isn’t legal to create a TWindow directly
- TWindow();
-
- public:
-
- virtual ~TWindow();
-
- // Event routing methods
-
- virtual Boolean EventFilter(EventRecord * theEvent);
-
- // Methods you shouldn’t need to override, but might need to
-
- enum WindowType
- {
- kModalWindow = 1000,
- kFloatingWindow,
- kNormalWindow
- };
-
- virtual void CreateWindow(WindowType typeOfWindowToCreate = kNormalWindow);
- virtual void Select(void);
- virtual void Drag(Point startPoint);
- virtual void Nudge(short horizontalDistance, short verticalDistance);
- virtual void Grow(Point startPoint);
- virtual void Zoom(short zoomState);
-
- virtual void ShowHide(Boolean showFlag);
-
-
- // Methods which MUST be overridden:
-
- virtual WindowRef MakeNewWindow(WindowRef behindWindow) = 0;
-
-
- // Methods which probably should be overridden
-
- virtual void AdjustCursor(EventRecord * anEvent);
- virtual void Idle(EventRecord * anEvent);
- virtual void Activate(Boolean activating);
- virtual void Draw();
- virtual void Click(EventRecord * anEvent);
- virtual void KeyDown(EventRecord * anEvent);
-
- virtual Boolean Close();
-
- virtual void GetPerfectWindowSize(Rect * perfectSize);
- virtual void GetWindowSizeLimits(Rect * limits);
- virtual void AdjustForNewWindowSize(Rect * oldRect,Rect * newRect);
-
-
- // Window property accessor methods…
- // …watch for new ones when we add scripting support
-
- virtual Boolean IsVisible();
- virtual Rect GetContentsBounds();
- virtual Boolean CanClose();
-
-
- // Methods for handling menus & menu commands
-
- virtual void AdjustMenusBeforeMenuSelection();
- virtual void AdjustMenusAfterMenuSelection();
- virtual Boolean DoMenuSelection(short menu, short item);
- virtual Boolean DoMenuCommand(MenuCommandID menuCommand);
-
- // Methods for use with the Drag Manager
-
- virtual OSErr HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag);
- virtual OSErr HandleDrop(DragReference theDragRef);
-
- virtual OSErr DragEnterWindow(DragReference theDrag);
- virtual OSErr DragInWindow(DragReference theDrag);
- virtual OSErr DragLeaveWindow(DragReference theDrag);
-
- static pascal OSErr CallDragTrackingHandler(DragTrackingMessage message,WindowRef theWindow,void *handlerRefCon,DragReference theDragRef);
- static pascal OSErr CallDragReceiveHandler(WindowRef theWindow, void *handlerRefCon,DragReference theDragRef);
-
- virtual Boolean IsPointInContentRgn(Point pt);
- virtual Boolean IsDragInContentRgn(DragReference dragRef);
-
- void FindScreenRectWithLargestPartOfWindow(WindowRef aWindow,Rect *theBestScreenRect, GDHandle * theBestDevice);
-
- protected:
- WindowRef fWindow;
- WindowType fWindowType;
-
- Boolean fIsDialogWindow;
- Boolean fIsVisible;
-
-
- // "globals"
-
- static UInt32 fgModalState;
-
- public:
-
- // Utility functions:
-
- static WindowRef FrontNonFloatingWindow();
- static WindowRef FrontModalWindow();
- static WindowRef LastModalWindow();
- static WindowRef FrontFloatingWindow();
- static WindowRef LastFloatingWindow();
- static WindowRef FrontNormalWindow();
-
-
- // Cool functions that replace Toolbox equivalents and/or add functionality
-
- static WindowRef GetNewWindow(short windowID, void *wStorage, WindowRef behind);
- static WindowRef NewWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowRef behind, Boolean goAwayFlag, long refCon);
- static void DrawGrowIcon(WindowRef theWindow);
-
- static void EnterModalState();
- static void ExitModalState();
-
- static void SuspendResumeWindows(Boolean resuming);
-
- static void HiliteAndActivateWindow(WindowRef aWindow, Boolean active);
- };
-
-
- // Utility Functions:
-
-
- TWindow * GetWindowObject(WindowRef aWindow);
-
-
-
- #endif
-